Page({

  /**
   * 页面的初始数据
   */
  data: {
    pageSize: 10, //每页查询大小
    currPage: 1, //当前页码
    nav: { //滚动导航
      list: [{name: '推荐', id: 0}, {name: '大板', id: 1},{name: '样品', id: 2},{name: '其他', id: 3}],
      active: 0, //当前选中的导航下标
      left: 0, //滚动值
      width: 130,
      offsetLeft: 0,
      todoTipNum: 0,
    },
    wareList: [
      {"checked":false,"ItemCode":"1AAG00001","ItemName":"FB-0006","Spec":"170X700/6"},
      {"checked":false,"ItemCode":"1AAG00002","ItemName":"FB-0005","Spec":"170X700/6"}
    ],
    scrollHeight: 1000,
    navtop: 90,
    showRadio: false,
    showRadioText: '多选',
    choseNames: [], //选中的名字列表
  },

  /**
   * 多选按钮点击
   */
  showCheckRadio: function (params) {
    var that = this;
    if (that.data.showRadio) {
      that.setData({
        showRadio: false,
        showRadioText: '多选'
      });
      that.resetCheckRadio();
    } else {
      that.setData({
        showRadio: true,
        showRadioText: '取消'
      });
    }
  },

  //取消多选模式
  cancelRadio: function (e) { 
    var that = this;
    if (that.data.showRadio) {
      that.showCheckRadio();
    }
  },

  /**
   * 重置
   */
  resetCheckRadio: function () {
    var that = this;
    that.data.wareList.forEach((val, key) => {
      val.checked = false;
      that.setData({
        [`wareList[${key}]`]: val,
      });
    });
    that.setData({
      choseNames:[]
    });
  },

  // 选中/取消
  checkboxChange: function(e) {
    let temp = e.currentTarget.dataset.item;
    let newChoseNames=this.data.choseNames;
    let number = -1;
    let check = false;
    newChoseNames.forEach(function(item,index){
      if (item.ItemCode == temp.ItemCode) {
        check = true;
        number = index;
        return;
      }
    });
    if (check) {
      newChoseNames.splice(number, 1)
    } else {
      newChoseNames.push(temp)
    }
    this.setData({
      choseNames: newChoseNames
    })
  },

  //点击导航 - 选中监听
  select: function (e) {
    this.changetab(e.currentTarget.dataset.idx);
  },
 
  //滚动页面，切换导航
  bindchange(e) {
    this.changetab(e.detail.current);
  },
 
  changetab: function (idx) {
    let _this = this,
    nav = this.data.nav;
    _this.cancelRadio();
    nav.active = idx;
    _this.setData({
      nav: nav,
    })
    this.setData({
      choseNames: []
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

})